<?php

class Father
{

    function __construct()
    {
//        echo "父类构造函数，如果子类没有重写构造函数将会调用这里。如果子类重写了构造函数则子类不用自动调用这个函数，而需要显示调用父类构造函数。";
    }


    public $m_fa = "fa";
    protected $m_fb = "fb";
    private $m_fc = "fc";

    public function getFa()
    {
        return $m_fa;
    }

    protected function getFb()
    {
        return $m_fb;
    }

    private function getFc()
    {
        return $m_fc;
    }

    public function getFaPrivate_1()
    {
        return $m_fc;
    }

    public function getFaPrivate_2()
    {
        return $m_fc;
    }

    public function getAll()
    {
        echo $this->m_fa, $this->m_fb, $this->m_fc;
        echo $this->getFa(), $this->getFb(), $this->getFc();
    }

}

class son extends father
{
    public function __construct()
    {
        parent::__construct(); //显示调用父类构造函数。
        echo "子类构造函数调用";
    }
}

$class_fa = "father";   //设置类名
$class_son = 'son';
$fa = new $class_fa();
$fa->getAll();
$son = new $class_son();
$son->getFa();
// 执行以下方法回报错，protected 无法在类外面进行调用的
// 报错信息：Fatal error: Uncaught Error: Call to protected method father::getFb()...
// $son->getFb();
// 执行以下方法回报错，private 无法被继承，也无法在类外面进行调用的
// 报错信息：Fatal error: Uncaught Error: Call to private method father::getFc()...
// $son->getFc();

$son->getFaPrivate_2();

//------------------------------------------------------------------------------------------------------------------
class students
{
    var $name, $age, $sex;

    function __construct($name, $age, $sex)
    {
        $this->name = $name;
        $this->age = $age;
        $this->sex = $sex;
    }
}

class master extends students
{
    var $hobby, $address;

    function __construct($name, $age, $sex, $hobby, $address)
    {
        parent::__construct($name, $age, $sex);
        $this->hobby = $hobby;
        $this->address = $address;
    }
}

?>